package cn.csxw.openchina.dagger2.presenter;

import java.util.ArrayList;

import javax.inject.Inject;

import cn.csxw.openchina.entity.bean.NewsBean;
import cn.csxw.openchina.entity.bean.OsChinaBean;
import cn.csxw.openchina.ui.fragment.syntheticalFragment.HotFragment;
import retrofit2.Call;

/**
 * Created by hp on 2017/1/15.
 */

public class HotPresenter extends BasePresenter {
    HotFragment mHotFragment;
    private ArrayList<NewsBean> mNewslist;

    @Inject
    public HotPresenter(HotFragment hotFragment) {
        mHotFragment = hotFragment;

    }

    @Override
    public void processData(OsChinaBean data) {
        if(data!=null){
            if(!hasMoreData(data)){
                mHotFragment.noMoreData();
                mHotFragment.mSrfLayout.setRefreshing(false);
            }else{
                mNewslist = (ArrayList<NewsBean>) data.newslist;
                if( mHotFragment.mHotAdapter.getData().size()!=0){
                    mHotFragment.mHotAdapter.addData(mNewslist);
                }else{
                    mHotFragment.mHotAdapter.setData(mNewslist);
                }
                mHotFragment.loadMoreCompleted();
                mHotFragment.mSrfLayout.setRefreshing(false);
            }
        }
    }

    /**
     * @param params 这是个数组
     */
    @Override
    public void callNetWork(Object... params) {
        if(params.length!=4||!(params[0] instanceof Integer)
                ||!(params[1] instanceof Integer)||!(params[2] instanceof String)||!(params[3] instanceof Integer)){
            throw new IllegalArgumentException("参数必需是int , int ,String,int,四个类型");
        }
        Call<OsChinaBean> hotInfo = mOsChinaServer.getHotInfo((int)params[0],(int)params[1],
                (String)params[2],(int)params[3]);
        hotInfo.enqueue(mCallback);
    }
}
